package com.dream21th.admin.utils;

import java.io.UnsupportedEncodingException;
import java.util.Arrays;
import java.util.Base64;

public class SignUtil {
    private final static String signKey = "ifxy8jvzf1q0f9uz";

    /**
     * 签名
     */
    public static String sign(String str, String token) throws UnsupportedEncodingException {

        char[] ch = str.toCharArray();

        Arrays.sort(ch);

        String sortStr = String.valueOf(ch).trim();

        String encode = Base64.getEncoder().encodeToString(sortStr.getBytes("UTF-8"));

        StringBuffer encoderStr = new StringBuffer(encode);

        if (token != null) {
            encoderStr.append(token);
        }

        encoderStr.append(signKey);

        String md5 = MD5.md5(encoderStr.toString()).toUpperCase();

        return md5;
    }
}
